package cn.hongyu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/*
文件上传具备三要素
1.文件上传项（<input type=file>）
2.表单提交方式 post表单
3.enctype是多部分表单形式<form method=post ebxtype=multipart/form-data>
 */
@Controller
public class FileController {
    @RequestMapping("/file1")
    @ResponseBody
    void file1(@RequestParam("username")String name, MultipartFile update) throws IOException {
        System.out.println(name);
        //获取文件名
        String filename = update.getOriginalFilename();
        update.transferTo(new File("d://upload//"+filename));
    }
}
